# 计科201132叶英杰
import os
import urllib.request
import requests
from bs4 import BeautifulSoup
url= "https://www.tute.edu.cn/xysh/yxtzsd.htm"
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
html = response.text
# 保存到本地
with open('tute.html', 'w', encoding='utf-8') as f:
    f.write(html)
# #读取文件中的图片标签的链接，用户决定读取次数
with open('tute.html', 'r', encoding='utf-8') as f:
    soup = BeautifulSoup(f, 'html.parser')
    souplist= soup.find_all('img')
    n = int(input("请输入要读取的次数："))
    for i in range(n):
        imglink="https://www.tute.edu.cn/"+souplist[i].get('src')
        print(imglink)
        img_data=requests.get(imglink).content
        with open('images/'+str(i)+'.jpg', 'wb') as f:
            f.write(img_data)





